package xq.gwt.ui.widgets.property;

import com.smartgwt.client.widgets.form.fields.IntegerItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;

import xq.gwt.mvc.controller.IntegerPropertyController;
import xq.gwt.mvc.model.IntegerPropertyModel;
import xq.gwt.mvc.view.IntegerPropertyView;

public class IntegerItemPropertyPresenter extends FormItemPropertyPresenter implements IntegerPropertyView{

	protected IntegerPropertyController controller;
	protected IntegerItem integerItem;
	
	public IntegerItemPropertyPresenter(){
		this.integerItem = new IntegerItem();
		init();
	}
	
	public IntegerItemPropertyPresenter(IntegerItem integerItem){
		this.integerItem = integerItem;
		init();
	}
	
	protected void init(){
		formItem = integerItem;
		this.integerItem.addChangedHandler(new ChangedHandler() {
			
			@Override
			public void onChanged(ChangedEvent event) {
				notifyViewChangedListeners();				
			}
		});
		controller = new IntegerPropertyController(this);
		super.controller = controller;
	}
	
	public void setModel(IntegerPropertyModel model){
		controller.setPropertyModel(model);
	}

	@Override
	public void setInteger(Integer val) {
		integerItem.setValue(val);
		
	}

	@Override
	public Integer getInteger() {		
		Integer value = null;
		try {
			value = (Integer)integerItem.getValue();
		} catch (Exception e) {
			
		}
		
		
		return value;
	}
}
